package StudentManagement1;

public class TestStudent1 {
    public static void main(String[] args) {
        // 创建对象（实例化类）
        Student stu1 = new Student();
        // 给对象属性赋值
        stu1.studentId = "2025001";
        stu1.name = "张三";

        // 创建第二个对象
        Student stu2 = new Student();
        stu2.studentId = "2025002";
        stu2.name = "李四";

        // 输出对象信息
        System.out.println("学生1: " + stu1.studentId + " " + stu1.name);
        System.out.println("学生2: " + stu2.studentId + " " + stu2.name);
    }

    public static class Student {
        // 私有属性（只能在本类访问）
        private String studentId;
        private String name;
        private int age;

        // getter方法：获取属性值
        public String getStudentId() {
            return studentId;
        }

        // setter方法：设置属性值
        public void setStudentId(String studentId) {
            this.studentId = studentId; // this表示当前对象
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        // 带验证的setter方法
        public void setAge(int age) {
            if (age >= 18 && age <= 30) {
                this.age = age;
            } else {
                System.out.println("年龄不合法（必须18-30岁）");
            }
        }
    }
}